<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="utf-8" lang="utf-8">
 <head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <title>
   日历类 - CodeIgniter 中文手册|用户手册|用户指南|Wiki文档
  </title>
  <link rel="shortcut icon" href="/user_guide/../images/design/favicon.ico" type="image/x-icon" />
  <link rel="stylesheet" type="text/css" media="all" href="/user_guide/userguide.css" />
  <link rel="search" href="/user_guide/../CodeIgniterSearch.xml" type="application/opensearchdescription+xml" title="CodeIgniter 搜索" />
  <link rel="canonical" href="/user_guide/libraries/calendar.html" />
  <script type="text/javascript" src="/user_guide/nav/nav.js">
  </script>
  <script type="text/javascript" src="/user_guide/nav/prototype.lite.js">
  </script>
  <script type="text/javascript" src="/user_guide/nav/moo.fx.js">
  </script>
  <script type="text/javascript" src="/user_guide/nav/user_guide_menu.js">
  </script>
  <meta name="robots" content="all" />
  <meta name="author" content="ExpressionEngine Dev Team" />
  <meta name="description" content="CodeIgniter 中文手册, CodeIgniter 用户指南, CodeIgniter User Guide, Wiki 文档" />
 </head>
 <body>
  <!-- START NAVIGATION -->
  <div id="nav">
   <div id="nav_inner">
    <script type="text/javascript">
     create_menu('/user_guide/');
    </script>
   </div>
  </div>
  <script type="text/javascript">
   _setNavigation();
  </script>
  <div id="nav2">
   <a name="top">
   </a>
   <a href="javascript:void(0);" onclick="myHeight.toggle();">
    <img src="/user_guide/images/nav_toggle_darker.jpg" width="154" height="43" border="0" title="切换目录" alt="切换目录" />
   </a>
  </div>
  <div id="masthead">
   <table cellpadding="0" cellspacing="0" border="0" style="width:100%">
    <tr>
     <td width="350">
      <h1>
       CodeIgniter 用户指南 版本 2.0.0
      </h1>
     </td>
     
     <td id="breadcrumb_right">
      <a href="/user_guide/toc.html">
       目录页
      </a>
     </td>
    </tr>
   </table>
  </div>
  <!-- END NAVIGATION -->
  <!-- START BREADCRUMB -->
  <table cellpadding="0" cellspacing="0" border="0" style="width:100%">
   <tr>
    <td id="breadcrumb">
     <a href="/" target="_blank">
      CodeIgniter 中国首页
     </a>
     &nbsp;&#8250;&nbsp;
     <a href="/user_guide/toc.html">用户指南目录</a>
     &nbsp;&#8250;&nbsp;日历类
    </td>
    <td id="searchbox">
     <form method="get" action="http://www.google.com/search" target="google_window">
      <input type="hidden" name="client" value="pub-0176846097796333" />
      <input type="hidden" name="forid" value="1" />
      <input type="hidden" name="ie" value="UTF-8" />
      <input type="hidden" name="oe" value="UTF-8" />
      <input type="hidden" name="as_sitesearch" id="as_sitesearch" value="codeigniter.org.cn/user_guide/" />
      搜索用户指南&nbsp;
      <input type="text" class="input" style="width:200px;" name="q" id="q" size="31" maxlength="255" value="" />
      &nbsp;
      <input type="submit" class="submit" name="sa" value="Go" />
     </form>
    </td>
   </tr>
  </table>
  <!-- END BREADCRUMB -->
  <div style="clear:both;text-align:right;padding: 6px 40px 0 0;">
   <a href="http://codeigniter.com/user_guide/libraries/calendar.html" target="_blank">
    查看原文
   </a>
  </div>
  <!--<br clear="all"  />-->
  <!-- START CONTENT -->
  <div id="content">
   <h1>
    日历类
   </h1>
   <p>
    日历类可以让你动态创建日历.并且用日历模板对创建的日历格式化,100%的控制它的样式.另外,你可以传送数据到你的日历单元格中(比如创建一个链接).
   </p>
   <h2>
    初始化类
   </h2>
   <p>
    和大多数其他CI中的类一样,在控制器中初始化日历类用
    <dfn>
     $this-&gt;load-&gt;library
    </dfn>
    函数:
   </p>
   <code>
    $this-&gt;load-&gt;library('calendar');
   </code>
   <p>
    导入之后,日历类可以这样使用:
    <dfn>
     $this-&gt;calendar
    </dfn>
   </p>
   <h2>
    显示一个日历
   </h2>
   <p>
    这是一个简单的例子告诉你如何去显示一个日历:
   </p>
   <code>
    $this-&gt;load-&gt;library('calendar');
    <br />
    <br />
    echo $this-&gt;calendar-&gt;generate();
   </code>
   <p>
    上面的代码将根据你服务器时间创建一个当前月/年的日历.
要显示一个指定月和年的日历，你要传递这些信息到日历生成函数:
   </p>
   <code>
    $this-&gt;load-&gt;library('calendar');
    <br />
    <br />
    echo $this-&gt;calendar-&gt;generate(
    <kbd>
     2006
    </kbd>
    ,
    <kbd>
     6
    </kbd>
    );
   </code>
   <p>
    上面的代码将创建一个显示2006年6月的日历.第一个参数指定了年，第二个参数指定了月.
   </p>
   <h2>
    传数据到单元格
   </h2>
   <p>
    增加数据到日历的单元格就要创建一个关联数组,在这个数组中索引是你想链接的天数value值包含你要传入的值.数组通过日历创建函数的第三个参数被传入.  参考下面这个例子:
   </p>
   <code>
    $this-&gt;load-&gt;library('calendar');
    <br />
    <br />
    $data = array(
    <br />
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;3&nbsp; => 'http://example.com/news/article/2006/03/',
    <br />
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;7&nbsp; => 'http://example.com/news/article/2006/07/',
    <br />
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;13 => 'http://example.com/news/article/2006/13/',
    <br />
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;26 => 'http://example.com/news/article/2006/26/'
    <br />
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;);
    <br />
    <br />
    echo $this-&gt;calendar-&gt;generate(
    <kbd>
     2006
    </kbd>
    ,
    <kbd>
     6
    </kbd>
    ,
    <var>
     $data
    </var>
    );
   </code>
   <p>
    使用上面的例子，天数3,7,13和26将变成链接指向你提供的URLs.
   </p>
   <p class="important">
    <strong>
     注意:
    </strong>
    默认情况,系统假定你的数组中已经包含了链接.
在下面解释日历模板部分你会看到你可以自定义数据如何被传入日历单元格以便你可以传不同类型的信息.
   </p>
   <h2>
    设置偏好
   </h2>
   <p>
    有 7 种偏好可以让你设置日历的各个方面.  偏好被设置成数组通过导入函数的第二个参数被导入. 下面是一个例子:
   </p>
   <code>
    $prefs = array (
    <br />
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'start_day'&nbsp;&nbsp;&nbsp; => 'saturday',
    <br />
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'month_type'&nbsp;&nbsp; => 'long',
    <br />
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'day_type'&nbsp;&nbsp;&nbsp;&nbsp; => 'short'
    <br />
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;);
    <br />
    <br />
    $this-&gt;load-&gt;library('calendar', $prefs);
    <br />
    <br />
    echo $this-&gt;calendar-&gt;generate();
   </code>
   <p>
    上面的代码将从礼拜六开始,用"长"月标题和"短"天数格式.更多关于偏好的信息请看下面.
   </p>
   <table cellpadding="0" cellspacing="1" border="0" style="width:100%" class="tableborder">
    <tr>
     <th>
      Preference
     </th>
     <th>
      Default&nbsp;Value
     </th>
     <th>
      Options
     </th>
     <th>
      Description
     </th>
    </tr>
    <tr>
     <td class="td">
      <strong>
       template
      </strong>
     </td>
     <td class="td">
      None
     </td>
     <td class="td">
      None
     </td>
     <td class="td">
      模板字符串. See the template section below.
     </td>
    </tr>
    <tr>
     <td class="td">
      <strong>
       local_time
      </strong>
     </td>
     <td class="td">
      time()
     </td>
     <td class="td">
      None
     </td>
     <td class="td">
      A Unix timestamp corresponding to the current time.
     </td>
    </tr>
    <tr>
     <td class="td">
      <strong>
       start_day
      </strong>
     </td>
     <td class="td">
      sunday
     </td>
     <td class="td">
      一周内的任一天（sunday,monday,ect.）
     </td>
     <td class="td">
      指定每周的第一天
     </td>
    </tr>
    <tr>
     <td class="td">
      <strong>
       month_type
      </strong>
     </td>
     <td class="td">
      long
     </td>
     <td class="td">
      long, short
     </td>
     <td class="td">
      月份的显示样式.long = January, short = Jan.
     </td>
    </tr>
    <tr>
     <td class="td">
      <strong>
       day_type
      </strong>
     </td>
     <td class="td">
      abr
     </td>
     <td class="td">
      long, short, abr
     </td>
     <td class="td">
      星期的显示样式long = Sunday, short = Sun, abr = Su.
     </td>
    </tr>
    <tr>
     <td class="td">
      <strong>
       show_next_prev
      </strong>
     </td>
     <td class="td">
      FALSE
     </td>
     <td class="td">
      TRUE/FALSE (boolean)
     </td>
     <td class="td">
      是否显示“上个月”和“下个月”链接.
     </td>
    </tr>
    <tr>
     <td class="td">
      <strong>
       next_prev_url
      </strong>
     </td>
     <td class="td">
      None
     </td>
     <td class="td">
      A URL
     </td>
     <td class="td">
      “上个月”和“下个月”链接地址.
     </td>
    </tr>
   </table>
   <h2>
    显示下一月/上一月链接
   </h2>
   <p>
    要让你的日历通过下一月/上一月链接动态的减少/增加,可以仿照下面的例子建立你的日历:
   </p>
   <code>
    $prefs = array (
    <br />
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'show_next_prev'&nbsp;&nbsp;=> TRUE,
    <br />
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'next_prev_url'&nbsp;&nbsp; => 'http://example.com/index.php/calendar/show/'
    <br />
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;);
    <br />
    <br />
    $this-&gt;load-&gt;library('calendar', $prefs);
    <br />
    <br />
    echo $this-&gt;calendar-&gt;generate(
    <var>
     $this-&gt;uri-&gt;segment(3)
    </var>
    ,
    <var>
     $this-&gt;uri-&gt;segment(4)
    </var>
    );
   </code>
   <p>
    在上面的例子中，你会注意到这几点:
   </p>
   <ul>
    <li>
     你必须把"show_next_prev"设置成TRUE.
    </li>
    <li>
     你必须在"next_prev_url"偏好中向日历提供 URL.
    </li>
    <li>
     你必须向日历创建函数提供"年"和"月"通过他们应该出现的URI段 (注意:  日历类自动添加年/月到你提供的base URL上.).
    </li>
   </ul>
   <h2>
    创建一个日历模板
   </h2>
   <p>
    通过创建一个日历模板你能够100%的控制界面设计. 日历的每一部分都要被放在一对伪变量中,像下面这样:
   </p>
   <code>
    $prefs['template'] = '
    <br />
    <br />
    &nbsp;&nbsp;&nbsp;
    <dfn>
     &#123;table_open&#125;
    </dfn>
    <var>
     &lt;table border="0" cellpadding="0" cellspacing="0">
    </var>
    <dfn>
     &#123;/table_open&#125;
    </dfn>
    <br />
    <br />
    &nbsp;&nbsp;&nbsp;
    <dfn>
     &#123;heading_row_start&#125;
    </dfn>
    <var>
     &lt;tr>
    </var>
    <dfn>
     &#123;/heading_row_start&#125;
    </dfn>
    <br />
    <br />
    &nbsp;&nbsp;&nbsp;
    <dfn>
     &#123;heading_previous_cell&#125;
    </dfn>
    <var>
     &lt;th>&lt;a href="
    </var>
    <kbd>
     &#123;previous_url&#125;
    </kbd>
    <var>
     ">&amp;lt;&amp;lt;&lt;/a>&lt;/th>
    </var>
    <dfn>
     &#123;/heading_previous_cell&#125;
    </dfn>
    <br />
    &nbsp;&nbsp;&nbsp;
    <dfn>
     &#123;heading_title_cell&#125;
    </dfn>
    <var>
     &lt;th colspan="
    </var>
    <kbd>
     &#123;colspan&#125;
    </kbd>
    <var>
     ">
    </var>
    <kbd>
     &#123;heading&#125;
    </kbd>
    <var>
     &lt;/th>
    </var>
    <dfn>
     &#123;/heading_title_cell&#125;
    </dfn>
    <br />
    &nbsp;&nbsp;&nbsp;
    <dfn>
     &#123;heading_next_cell&#125;
    </dfn>
    <var>
     &lt;th>&lt;a href="
    </var>
    <kbd>
     &#123;next_url&#125;
    </kbd>
    <var>
     ">&amp;gt;&amp;gt;&lt;/a>&lt;/th>
    </var>
    <dfn>
     &#123;/heading_next_cell&#125;
    </dfn>
    <br />
    <br />
    &nbsp;&nbsp;&nbsp;
    <dfn>
     &#123;heading_row_end&#125;
    </dfn>
    <var>
     &lt;/tr>
    </var>
    <dfn>
     &#123;/heading_row_end&#125;
    </dfn>
    <br />
    <br />
    &nbsp;&nbsp;&nbsp;
    <dfn>
     &#123;week_row_start&#125;
    </dfn>
    <var>
     &lt;tr>
    </var>
    <dfn>
     &#123;/week_row_start&#125;
    </dfn>
    <br />
    &nbsp;&nbsp;&nbsp;
    <dfn>
     &#123;week_day_cell&#125;
    </dfn>
    <var>
     &lt;td>
    </var>
    <dfn>
     &#123;week_day&#125;
    </dfn>
    <var>
     &lt;/td>
    </var>
    <dfn>
     &#123;/week_day_cell&#125;
    </dfn>
    <br />
    &nbsp;&nbsp;&nbsp;
    <dfn>
     &#123;week_row_end&#125;
    </dfn>
    <var>
     &lt;/tr>
    </var>
    <dfn>
     &#123;/week_row_end&#125;
    </dfn>
    <br />
    <br />
    &nbsp;&nbsp;&nbsp;
    <dfn>
     &#123;cal_row_start&#125;
    </dfn>
    <var>
     &lt;tr>
    </var>
    <dfn>
     &#123;/cal_row_start&#125;
    </dfn>
    <br />
    &nbsp;&nbsp;&nbsp;
    <dfn>
     &#123;cal_cell_start&#125;
    </dfn>
    <var>
     &lt;td>
    </var>
    <dfn>
     &#123;/cal_cell_start&#125;
    </dfn>
    <br />
    <br />
    &nbsp;&nbsp;&nbsp;
    <dfn>
     &#123;cal_cell_content&#125;
    </dfn>
    <var>
     &lt;a href="
    </var>
    <kbd>
     &#123;content&#125;
    </kbd>
    <var>
     ">
    </var>
    <kbd>
     &#123;day&#125;
    </kbd>
    <var>
     &lt;/a>
    </var>
    <dfn>
     &#123;/cal_cell_content&#125;
    </dfn>
    <br />
    &nbsp;&nbsp;&nbsp;
    <dfn>
     &#123;cal_cell_content_today&#125;
    </dfn>
    <var>
     &lt;div class="highlight">&lt;a href="
    </var>
    <kbd>
     &#123;content&#125;
    </kbd>
    <var>
     ">
    </var>
    <kbd>
     &#123;day&#125;
    </kbd>
    <var>
     &lt;/a>&lt;/div>
    </var>
    <dfn>
     &#123;/cal_cell_content_today&#125;
    </dfn>
    <br />
    <br />
    &nbsp;&nbsp;&nbsp;
    <dfn>
     &#123;cal_cell_no_content&#125;
    </dfn>
    <var>
    </var>
    <kbd>
     &#123;day&#125;
    </kbd>
    <var>
    </var>
    <dfn>
     &#123;/cal_cell_no_content&#125;
    </dfn>
    <br />
    &nbsp;&nbsp;&nbsp;
    <dfn>
     &#123;cal_cell_no_content_today&#125;
    </dfn>
    <var>
     &lt;div class="highlight">
    </var>
    <kbd>
     &#123;day&#125;
    </kbd>
    <var>
     &lt;/div>
    </var>
    <dfn>
     &#123;/cal_cell_no_content_today&#125;
    </dfn>
    <br />
    <br />
    &nbsp;&nbsp;&nbsp;
    <dfn>
     &#123;cal_cell_blank&#125;
    </dfn>
    <var>
     &amp;nbsp;
    </var>
    <dfn>
     &#123;/cal_cell_blank&#125;
    </dfn>
    <br />
    <br />
    &nbsp;&nbsp;&nbsp;
    <dfn>
     &#123;cal_cell_end&#125;
    </dfn>
    <var>
     &lt;/td>
    </var>
    <dfn>
     &#123;/cal_cell_end&#125;
    </dfn>
    <br />
    &nbsp;&nbsp;&nbsp;
    <dfn>
     &#123;cal_row_end&#125;
    </dfn>
    <var>
     &lt;/tr>
    </var>
    <dfn>
     &#123;/cal_row_end&#125;
    </dfn>
    <br />
    <br />
    &nbsp;&nbsp;&nbsp;
    <dfn>
     &#123;table_close&#125;
    </dfn>
    <var>
     &lt;/table>
    </var>
    <dfn>
     &#123;/table_close&#125;
    </dfn>
    <br />
    ';
    <br />
    <br />
    $this-&gt;load-&gt;library('calendar', $prefs);
    <br />
    <br />
    echo $this-&gt;calendar-&gt;generate();
   </code>
   <p>
    &nbsp;
   </p>
   <div id="Contributors">
    翻译贡献者:
airwin, Hex, huanxiangwu, kissmumu, Roger_masslong
   </div>
   <div id="DocDate">
    最后修改: 2009-09-12 15:25:03
   </div>
  </div>
  <!-- END CONTENT -->
  <div id="footer">
   <p>
    上一个主题:&nbsp;&nbsp;
    <a href="/user_guide/libraries/benchmark.html">
     基准测试类
    </a>
    &nbsp;&nbsp;&middot;&nbsp;&nbsp;
    <a href="#top">
     页首
    </a>
    &nbsp;&middot;&nbsp;&nbsp;
    <a href="/user_guide/toc.html">用户指南目录</a>
    &nbsp;&nbsp;&middot;&nbsp;&nbsp;下一个主题:&nbsp;&nbsp;
    <a href="/user_guide/libraries/cart.html">
     购物车类
    </a>
   </p>
   <p>
    <a href="http://codeigniter.com">
     CodeIgniter
    </a>
    &nbsp;&middot;&nbsp; 版权所有 &#169; 2006-2011 &nbsp;&middot;&nbsp;
    <a href="http://ellislab.com/">
     Ellislab, Inc.
    </a>
   </p>
   <p>
    中文化:
    <a href="">
     CodeIgniter 中国
    </a>
    &nbsp;&middot;&nbsp; 制作: Hex &nbsp;&middot;&nbsp; 版本: 1.20 &nbsp;&middot;&nbsp; 鸣谢: 子非鱼
   </p>
  </div>
  
  <div style="display:none">
   
   <noscript>
    <a href="http://www.51.la/?3289908" target="_blank">
     <img alt="我要啦免费统计" src="http://img.users.51.la/3289908.asp" style="border:none" />
    </a>
   </noscript>
  </div>
 </body>
</html>